﻿using System;
using System.Net;

namespace Lunexx.Config
{
    public class MasterSettings
    {
       
        #region Private Members
        //Default Settings for MasterSocket class
        int m_port = 15550;
        string m_listenIp = "127.0.0.1";
        string m_serverHost = "u-lunia-lb00.pubgame.ijji.com";
        IPAddress m_serverIp = null;

        #endregion
        #region Public Members
        public string ListenIpString
        {
            get { return m_listenIp; }
            set { m_listenIp = value; }
        }
        public int Port
        {
            get { return m_port; }
            set { m_port = value; }
        }
        public IPAddress ListenIP
        {
            get { return IPAddress.Parse(m_listenIp); }
            set { m_listenIp = value.ToString(); }
        }
        
        public IPEndPoint EndPoint
        {
            get { return new IPEndPoint(ServerIP,m_port); }
            set { ListenIP = value.Address; m_port = value.Port; }
        }
        public IPEndPoint ListenEndPoint
        {
            get { return new IPEndPoint(ListenIP, Port); }
            set { ListenIP = value.Address; Port = value.Port; }
        }
        public string ServerHost
        {
            get { return m_serverHost; }
            set { m_serverHost = value; }
        }
        /// <summary>
        /// Resolves Server hostname and returns a random IP assigned to that host.
        /// </summary>
        public IPAddress ServerIP
        {
            get
            {
                if (m_serverIp == null)
                {
                    Random randomIP = new Random();
                    IPHostEntry serverHostEntry = Dns.GetHostEntry(m_serverHost);
                    return serverHostEntry.AddressList[randomIP.Next(0, serverHostEntry.AddressList.Length)];
                }
                else { return m_serverIp; }
            }
            set
            {
                m_serverIp = value;
            }
        }

        #endregion
    }
}
